package com.health.call.service.impl;

import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.health.call.Pojo.AliCallLogPojo;
import com.health.call.Pojo.CLCallLogPojo;
import com.health.call.Pojo.XWCallLogPojo;
import com.health.call.service.CallLogService;
import com.health.call.utils.CopyUtil;
import com.health.call.utils.HttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Service
public class CallLogServiceImpl implements CallLogService {


    private static final String API_URL_CL = "http://localhost:8082/ierp/kapi/app/rm_mapp/Calllog";

    private static JsonParser jsonParser = new JsonParser();



     //创蓝通话记录
    @Override
    public JsonObject ClCallLog(CLCallLogPojo clCallLogPojo) {
        Map map = JSON.parseObject(JSON.toJSONString(clCallLogPojo), Map.class);
        String result = HttpUtils.post(API_URL_CL,map);
        return jsonParser.parse(result).getAsJsonObject();
    }

    //阿里通话记录
    @Override
    public JsonObject ALiCallLog(AliCallLogPojo aliCallLogPojo) {

        return null;
    }

     // 西沃通话记录
    @Override
    public JsonObject XWCallLog(XWCallLogPojo xwCallLogPojo) {
        final String API_URL_XW = "http://47.108.197.168:8078/cc-crm/httpTriggerInfo.do?method=invokeTrigger&actionKey=loadCallStatList&corpVccId=999999&vccNo="+xwCallLogPojo.getVccNo()+"&startTime="+xwCallLogPojo.getStartTime()+"&endTime="+xwCallLogPojo.getEndTime()+"&unAuthChk=true";
        Map<String,String> params = new HashMap<String,String>();
            params.put("starttime",xwCallLogPojo.getStartTime());
            params.put("endtime",xwCallLogPojo.getEndTime());
            params.put("vccNo",xwCallLogPojo.getVccNo());
            String result = HttpUtils.post(API_URL_XW,params);
            return JsonParser.parseString(result).getAsJsonObject();
        }

    }

